# 涉及两个类：StringIO和ByteIO
from io import StringIO, BytesIO
# simple_server代码中有StringIO的应用
# from wsgiref import simple_server

s_io = StringIO()
s_io.write('hello')  # 数据写入到内存
s_io.write(' world')
print(s_io.getvalue())

# print()中的file参数传入的是文件流对象，而不是文件名
# print('hello', file = open('test_file.txt', mode='w'))
print('hi!', file=s_io)
print(s_io.getvalue())

b_io = BytesIO()
b_io.write('你好, tom and jerry!'.encode('utf8'))
print(b_io.getvalue().decode('utf8'))
